package com.course.redis.controller;

import com.course.common.response.BaseResponse;
import com.course.redis.service.NearMeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @PROJECT_NAME: course
 * @DESCRIPTION:
 * @Author: 涂玄武
 * @DATE: 2021/6/28 16:22
 */
@RestController
@RequestMapping("nearme")
public class NearMeController extends BaseController {

    @Resource
    private NearMeService nearMeService;

    /**
     * 更新用户坐标
     *
     * @param access_token
     * @param lon
     * @param lat
     * @return
     */
    @PostMapping("updateUserLocation")
    public BaseResponse updateUserLocation(String access_token,
                                           @RequestParam Float lon,
                                           @RequestParam Float lat) {
        nearMeService.updateUserLocation(loadSignInDinerInfo(access_token), lon, lat);
        return new BaseResponse().success("更新成功");
    }

    /**
     * 获取附近的人
     * @param access_token
     * @param radius
     * @param lon
     * @param lat
     * @return
     */
    @GetMapping("nearMe")
    public BaseResponse nearMe(String access_token,
                               Integer radius,
                               Float lon, Float lat) {
        return new BaseResponse().success(nearMeService.findNearMe(loadSignInDinerInfo(access_token),radius,lon,lat));
    }

}
